package bosque.unc.gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.JToggleButton;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.JButton;

import bosque.unc.enumerations.Direccion;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
import java.awt.Toolkit;

public class EspejoSecundarioGUI extends JFrame {

	private JPanel contentPane;
	
	private JToggleButton tgbtnStop;
	private JToggleButton tgbtnAcercar;
	private JToggleButton tgbtnAlejar;
	private JLabel lblAcercar;
	private JLabel lblAlejar;
	private JButton btnResetearPalpador;
	private JButton btnBuscarPalpador;
	private JLabel lblEstado;
	private static Scoba scoba;
	

	private JLabel lblConexion;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				
				try
				{
					System.out.println("Look and Fell: " + UIManager.getSystemLookAndFeelClassName());
					UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
				}
				catch (Exception ex)
				{
					System.out.println("Failed loading L&F: ");
					System.out.println(ex);
				}
				
				try {
					EspejoSecundarioGUI frame = new EspejoSecundarioGUI(scoba);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public EspejoSecundarioGUI(Scoba s) {
		this.scoba = s;
		inicialize();
		}
	public void inicialize()
	{
		setIconImage(Toolkit.getDefaultToolkit().getImage("D:\\WorkTesis\\Scoba\\src\\bosque\\unc\\gui\\resources\\espejo.png"));	
		setTitle("Espejo Secundario");		
		setBounds(100, 100, 321, 342);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		tgbtnAcercar = new JToggleButton("");
		tgbtnAcercar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				
				if(tgbtnAcercar.isSelected())
				{
				
					tgbtnAlejar.setEnabled(false);
					tgbtnStop.setEnabled(true);
					tgbtnStop.setSelected(false);
					scoba.getEspejoSecundario().mover(Direccion.ADENTRO);
				
				}
				else
				{
					tgbtnAcercar.setSelected(true);
				}
		
			}
		});
		tgbtnAcercar.setIcon(new ImageIcon( getClass().getResource("resources/der.png" )));
		tgbtnAcercar.setBounds(50, 41, 32, 32);
		contentPane.add(tgbtnAcercar);
		
		tgbtnAlejar = new JToggleButton("");
		tgbtnAlejar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				if(tgbtnAlejar.isSelected())
				{
				
					tgbtnAcercar.setEnabled(false);
					tgbtnStop.setEnabled(true);
					tgbtnStop.setSelected(false);
					scoba.getEspejoSecundario().mover(Direccion.AFUERA);
								
				}
				else
				{
					tgbtnAlejar.setSelected(true);
				}
				
			}
		});
		tgbtnAlejar.setIcon(new ImageIcon( getClass().getResource("resources/izq.png" )));
		tgbtnAlejar.setBounds(224, 41, 32, 32);
		contentPane.add(tgbtnAlejar);
		
		tgbtnStop = new JToggleButton("");
		tgbtnStop.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				if(tgbtnStop.isSelected()){
					
					enablebuttonsEspejoSecundario();
					tgbtnStop.setEnabled(false);
					tgbtnAlejar.setSelected(false);
					tgbtnAcercar.setSelected(false);
					scoba.getEspejoSecundario().mover(Direccion.PARADO);
					}
					else
					{
						tgbtnStop.setSelected(true);
						
					}
							
			}
		});
		tgbtnStop.setIcon(new ImageIcon( getClass().getResource("resources/stop.png" )));
		tgbtnStop.setOpaque(true);
		tgbtnStop.setEnabled(false);
		tgbtnStop.setContentAreaFilled(false);
		tgbtnStop.setBorderPainted(false);
		tgbtnStop.setBounds(125, 32, 55, 53);
		contentPane.add(tgbtnStop);
		
		lblAcercar = new JLabel("Acercar");
		lblAcercar.setHorizontalAlignment(SwingConstants.CENTER);
		lblAcercar.setBounds(37, 84, 55, 14);
		contentPane.add(lblAcercar);
		
		lblAlejar = new JLabel("Alejar");
		lblAlejar.setHorizontalAlignment(SwingConstants.CENTER);
		lblAlejar.setBounds(213, 84, 55, 14);
		contentPane.add(lblAlejar);
		
		btnResetearPalpador = new JButton("Resetear Palpador");
		btnResetearPalpador.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				
				
				
				
			}
		});
		btnResetearPalpador.setBounds(82, 157, 135, 23);
		contentPane.add(btnResetearPalpador);
		
		btnBuscarPalpador = new JButton("Buscar Palpador");
		btnBuscarPalpador.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				
				
				
			}
		});
		btnBuscarPalpador.setBounds(82, 205, 135, 23);
		contentPane.add(btnBuscarPalpador);
		
		lblEstado = new JLabel("Estado :");
		lblEstado.setBounds(53, 264, 56, 14);
		contentPane.add(lblEstado);
		
		lblConexion = new JLabel("Sin Conexion");
		lblConexion.setForeground(Color.RED);
		lblConexion.setBounds(119, 264, 116, 14);
		contentPane.add(lblConexion);
	}
	
	
	/**
	 * 
	 * habilita los botones acercar y alejar del espejo secundario
	 */
	public void enablebuttonsEspejoSecundario(){
		
		tgbtnAlejar.setEnabled(true);
		tgbtnAcercar.setEnabled(true);
		
	}

	
	public JLabel getLblEstado() {
		return lblEstado;
	}

	public void setLblEstado(JLabel lblEstado) {
		this.lblEstado = lblEstado;
	}

	public JLabel getLblConexion() {
		return lblConexion;
	}

	public void setLblConexion(JLabel lblConexion) {
		this.lblConexion = lblConexion;
	}

	
}
